import 'package:auto_route/auto_route.dart';
import 'package:casdon/app/config/theme/theme_extention.dart';
import 'package:casdon/common/widget/common_app_bar.dart';
import 'package:casdon/modules/me/ui/screen/browsing_life_history_screen.dart';
import 'package:casdon/modules/me/ui/screen/browsing_recipe_history_screen.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';

/// 浏览记录页面
/// @RoutePage()
@RoutePage()
class BrowsingHistoryScreen extends ConsumerStatefulWidget {
  const BrowsingHistoryScreen({super.key});

  @override
  ConsumerState<BrowsingHistoryScreen> createState() =>
      _BrowsingHistoryScreenState();
}

class _BrowsingHistoryScreenState extends ConsumerState<BrowsingHistoryScreen>
    with SingleTickerProviderStateMixin {
  late TabController _tabController;
  final List<String> tabs = ["看过菜谱", "看过帖子"];

  @override
  void initState() {
    super.initState();
    _tabController = TabController(length: tabs.length, vsync: this);
  }

  @override
  void dispose() {
    _tabController.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: CommonAppBar(title: "浏览记录"),
      body: Column(
        children: [
          Container(
            color: Colors.white,
            child: TabBar(
              controller: _tabController,
              tabs: tabs.map((tab) => Tab(text: tab)).toList(),
              labelColor: context.colorScheme.primary,
              labelStyle: context.textTheme.bodyLarge?.copyWith(
                color: context.colorScheme.primary,
              ),
              indicatorPadding: const EdgeInsets.symmetric(horizontal: 16),
              unselectedLabelColor: context.customColorThemeNonNull.textColor1,
              unselectedLabelStyle: context.textTheme.bodyMedium?.copyWith(
                color: context.colorScheme.primary,
              ),
              indicatorColor: context.colorScheme.primary,
              dividerColor: Colors.transparent,
            ),
          ),
          Expanded(
            child: TabBarView(
              controller: _tabController,
              children: tabs.map((tab) {
                return _buildTabContent(tab);
              }).toList(),
            ),
          ),
        ],
      ),
    );
  }

  Widget _buildTabContent(String tabName) {
    switch (tabName) {
      case "看过菜谱":
        return const BrowsingRecipeHistoryScreen();
      case "看过帖子":
        return const BrowsingLifeHistoryScreen();
      default:
        return Center(child: Text('$tabName 页面内容'));
    }
  }
}
